import java.util.Arrays;

public class Test2 {
    //合并排序
    public static int[] sort(int[] array1, int[] array2){
        int[] tmp = new int[array1.length+array2.length];
        int n = 0;
        int a = 0;
        int a1 = array1.length-1;
        int b = 0;
        int b1 = array2.length-1;
        while(a <= a1 && b <= b1){
            if(array1[a] <= array2[b]){
                tmp[n++] = array1[a++];
            }
           else{
                tmp[n++] = array2[b++];
            }
        }
        while(a <= a1){
            tmp[n++] = array1[a++];
        }
        while(b <= b1){
            tmp[n++] = array2[b++];
        }
        return tmp;
    }
    public static void main(String[] args) {
        int[] array1 = {2,4,5,7,8};
        int[] array2 = {2,3,6,9};
        int[] ret = sort(array1,array2);
        System.out.println(Arrays.toString(ret));
    }
}
